package org.wtframework.platform.web.mvc.action.impl;

import org.openredhead.springx.core.web.mvc.support.ActionValueAssistant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.wtframework.platform.server.log.SystemControllerLog;
import org.wtframework.website.server.service.InternalEmailService;
import org.wtframework.website.server.service.NoticeBoardService;

@Controller
@RequestMapping("/back")
public class BackManagerActionController {
	
	@Autowired
	private NoticeBoardService noticeBoardService;
	
	@Autowired
	private InternalEmailService internalEmailService;
	
	private static String BASE_URL = "admin/back_layui/base";
	
	/**
	 * 
	 * <B>方法描述：</B>（后台管理页面） <br/>
	 *
	 * <B>作者：	 </B> 梁卓文 <br/>
	 * @param modelMap
	 * @param actionValueAssistant
	 * @return
	 */
	@RequestMapping("/index") 
	@SystemControllerLog(description="进入管理后台")
	public String index(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

//		return "back/index";
		modelMap.put("noticeBoardPage", noticeBoardService.findAllNotice(1, 1));
		
		return "admin/back_layui/index";
	}
	
	/**
	 * 
	 * <B>方法描述：</B>（后台欢迎页面） <br/>
	 *
	 * <B>作者：	 </B> 梁卓文 <br/>
	 * @param modelMap
	 * @param actionValueAssistant
	 * @return
	 */
	@RequestMapping("/welcome") 
	public String welcome(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {
		
//		return "back/welcome";
		return "admin/back_layui/welcome";
	}
	
	@RequestMapping("/notFound") 
	@SystemControllerLog(description="找不到页面")
	public String notFound(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {
		
		return BASE_URL+"/notFound";
	}
	
	@RequestMapping("/linkMan") 
	public String linkMan(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {
		Integer currentPage=actionValueAssistant.get(Integer.class, "page");
		if(currentPage==null){
			currentPage=1;
		}
		
		modelMap.put("linkManPage",internalEmailService.findLinkMan(currentPage, 10));
		return BASE_URL+"/linkMan";
	}
	
	@RequestMapping("/inbox") 
	public String inbox(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {
		Integer currentPage=actionValueAssistant.get(Integer.class, "page");		
		if(currentPage==null){
			currentPage=1;
		}		
		modelMap.put("emailPage",internalEmailService.findEmail(currentPage, 10));
		
		actionValueAssistant.addToModelMap(modelMap);
		return BASE_URL+"/inbox";
	}
	
}
